import { AxiosResponse } from 'axios'
import Service from '../../request'

export interface WorkspaceBaseInfo {
  _id: string
  name: string
  uid: string
  createdAt: string
}

export interface WorkspaceDetail {
  id: string
  name: string
  createTime: number
  tabsInfo: [TabCollection]
  customedTabsInfo: [TabCollection]
}

export interface TabCollection {
  id: string
  createTime: number
  tabItems: [TabItem]
}

export interface TabItem {
  _id: string
  name: number
  url: string
}

export interface AddWorkspaceInfo {
  name: string
}

export function getWorkSpaceBaseInfo() {
  return Service.get<Response<WorkspaceBaseInfo[]>>('/workspace')
}

export function getWorkSpaceDetail(wid: string) {
  return Service.get<Response<WorkspaceDetail>>(`/workspace/${wid}`)
}

export function addWorkSpace(workspaceInfo: AddWorkspaceInfo) {
  return Service.post<
    AddWorkspaceInfo,
    AxiosResponse<Response<{ message: string }>>
  >('/workspace', workspaceInfo)
}

export function modifyName(wid: string, workspaceInfo: AddWorkspaceInfo) {
  return Service.patch<
    AddWorkspaceInfo,
    AxiosResponse<Response<{ message: string }>>
  >(`/workspace/${wid}`, workspaceInfo)
}

export function delWorkspace(wid: string) {
  return Service.delete(`/workspace/${wid}`)
}
